//
//  HomeWaterFlowCell.m
//  YiKao2
//
//  Created by Mac Jc on 15/7/29.
//  Copyright (c) 2015年 Mac Jc. All rights reserved.
//

#import "HomeWaterFlowCell.h"
#import "AllHeader.h"

const CGFloat kTMPhotoQuiltViewMargin = 0;

@implementation HomeWaterFlowCell




@synthesize photoView = _photoView;
@synthesize tagLabel = _tagLabel;

- (void)dealloc
{
    [_photoView release],
    _photoView = nil;
    [_tagLabel release],
    _tagLabel = nil;
    
    
    [super dealloc];
}

//重写初始化方法
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self.layer setCornerRadius:5];
        [UIView viewShadowColor:self];
//        [self setViewFrame];
    }
    return self;
}


- (UIView *)textView
{
    if (!_textView) {
        _textView = [[UIView alloc] init];
        _textView.backgroundColor = [UIColor whiteColor];
    }
    return _textView;
}

- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor lightGrayColor];
        _lineView.alpha = 0.5;
        [self addSubview:_lineView];
    }
    return _lineView;
}

- (UIImageView *)photoView {
    if (!_photoView) {
        _photoView = [[UIImageView alloc] init];
        _photoView.contentMode = UIViewContentModeScaleAspectFill;
        _photoView.backgroundColor = kRandomColor;
        [_photoView setContentMode:(UIViewContentModeScaleAspectFill)];
        _photoView.clipsToBounds = YES;
        

        [self addSubview:_photoView];
    }
    return _photoView;
}

- (UILabel *)tagLabel {
    if (!_tagLabel) {
        _tagLabel = [[UILabel alloc] init];
        _tagLabel.textColor = kCustomColor(150, 150, 150, 1);
        _tagLabel.font = [UIFont systemFontOfSize:11];
        [self addSubview:_tagLabel];
    }
    return _tagLabel;
}

- (UILabel *)authorLabel
{
    if (!_authorLabel) {
        _authorLabel = [[UILabel alloc] init];
        _authorLabel.textColor = kCustomColor(40, 40, 50, 1);
        _authorLabel.font = [UIFont systemFontOfSize:10];
        [self addSubview:_authorLabel];
    }
    return _authorLabel;
}


- (UIImageView *)iconView
{
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
        [_iconView.layer setCornerRadius:13];
        [_iconView.layer setMasksToBounds:YES];
        [_iconView setContentMode:(UIViewContentModeScaleAspectFill)];
        [self addSubview:_iconView];
    }
    return _iconView;
}

- (UIImageView *)viewNumImageView
{
    if (!_viewNumImageView) {
        _viewNumImageView = [[UIImageView alloc] init];
        _viewNumImageView.image = [UIImage imageNamed:@"ViewNum"];
        [self addSubview:_viewNumImageView];
    }
    return _viewNumImageView;
}

- (UILabel *)viewNumLabel
{
    if (!_viewNumLabel) {
        _viewNumLabel = [[UILabel alloc] init];
        _viewNumLabel.textColor = kCustomColor(180, 180, 180, 1);
        _viewNumLabel.font = [UIFont boldSystemFontOfSize:11];
//        _viewNumLabel.text = @"57";
        [self addSubview:_viewNumLabel];
    }
    return _viewNumLabel;
}

- (UIImageView *)CommentNumIcon
{
    if (!_CommentNumIcon) {
        _CommentNumIcon = [[UIImageView alloc] init];
        _CommentNumIcon.image = [UIImage imageNamed:@"CommentNumIcon"];
        [self addSubview:_CommentNumIcon];
    }
    return _CommentNumIcon;
}

- (UILabel *)CommentNumLabel
{
    if (!_CommentNumLabel) {
        _CommentNumLabel = [[UILabel alloc] init];
        _CommentNumLabel.textColor = kCustomColor(180, 180, 180, 1);
        _CommentNumLabel.font = [UIFont boldSystemFontOfSize:11];
//        _CommentNumLabel.text = @"134";
        [self addSubview:_CommentNumLabel];
    }
    return _CommentNumLabel;
}

- (UILabel *)describeLabel
{
    if (!_describeLabel) {
        _describeLabel = [[UILabel alloc] init];
        //        _titleLabel.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
        _describeLabel.textColor = kCustomColor(40, 40, 50, 1);
        _describeLabel.font = [UIFont systemFontOfSize:11];
//        _describeLabel.text = @"This is describe label...";
        [self addSubview:_describeLabel];
    }
    return _describeLabel;
}



- (void)layoutSubviews
{
//    self.photoView.frame = CGRectMake(0, 0, self.bounds.size.width, ((_photoView.image.size.height / _photoView.image.size.width) * self.bounds.size.width));
    self.photoView.frame = CGRectMake(0, 0, self.bounds.size.width, 200);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_photoView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:(CGSizeMake(5, 5))];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = _photoView.bounds;
    maskLayer.path = maskPath.CGPath;
    _photoView.layer.mask = maskLayer;
    
    self.textView.frame = CGRectMake(0, self.bounds.size.height - 104 * HEIGHT, self.bounds.size.width,52 * HEIGHT);
    self.lineView.frame = CGRectMake(0, self.bounds.size.height - 50 * HEIGHT, self.bounds.size.width, 0.5 * HEIGHT);
    self.tagLabel.frame = CGRectMake(43, self.bounds.size.height - 42 * HEIGHT, self.bounds.size.width - 60, 20 * HEIGHT);
    self.authorLabel.frame = CGRectMake(43, self.bounds.size.height - 28.5 * HEIGHT, self.bounds.size.width - 60, 20 * HEIGHT);
    self.iconView.frame = CGRectMake(10, self.bounds.size.height - 39 * HEIGHT, 26, 26);
    
    self.viewNumImageView.frame = CGRectMake(10, self.bounds.size.height - 70 * HEIGHT, 15, 12);
    self.viewNumLabel.frame = CGRectMake(self.viewNumImageView.right + 2, self.bounds.size.height - 74 * HEIGHT, 100, 20 * HEIGHT);
    
    self.CommentNumIcon.frame = CGRectMake(60, self.bounds.size.height - 70 * HEIGHT, 15, 12);
    self.CommentNumLabel.frame = CGRectMake(self.CommentNumIcon.right + 2, self.bounds.size.height - 72 * HEIGHT, 100, 15 * HEIGHT);
    
    self.describeLabel.frame = CGRectMake(10, self.bounds.size.height - 90 * HEIGHT, 150 * WIDTH, 15);
    
}


- (void)setModel:(HomeListModel *)model
{
    _model = model;
    
    [_photoView sd_setImageWithURL:[NSURL URLWithString:_model.img] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageLowPriority ];
    
    [_iconView sd_setImageWithURL:[NSURL URLWithString:_model.userFace] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageLowPriority ];
    
//    UIImage *image = _photoView.image;
//    if (image != nil)
//    {
//        CGFloat cellHeight = image.size.height / image.size.width * 172.5 * WIDTH;
//        _photoImageHeight = cellHeight;
//        self.photoView.frame = CGRectMake(0, 0, self.bounds.size.width, _photoImageHeight);
//    }

    self.authorLabel.text = _model.nickName;
    self.tagLabel.text = _model.tags;
    _describeLabel.text = _model.info;
    self.viewNumLabel.text = _model.views;
    self.CommentNumLabel.text = _model.comments;

}



@end
